var e = require;
var t = module;
var n = exports;
var o =
    (this && this.__assign) ||
    function() {
        return (o =
            Object.assign ||
            function(e) {
                for (var t, n = 1, o = arguments.length; n < o; n++)
                    for (var i in (t = arguments[n])) Object.prototype.hasOwnProperty.call(t, i) && (e[i] = t[i]);
                return e;
            }).apply(this, arguments);
    };
Object.defineProperty(n, "__esModule", { value: !0 }), (n.userData = n.UserData = void 0);
var r = e("index"),
    i = e("guide-manager"),
    a = e("player-info"),
    s = e("env"),
    c = e("events"),
    l = e("wechat-ad"),
    u = e("time"),
    p = { effectSound: !0, bgmSound: !0, vibrate: !0 },
    e =
    ((h.prototype.onLogin = function(e) {
            this.loadSetting(), this.getLocalData(), u.time.sync(e), (this.loginAt = Date.now());
            var t = this.basic;
            (t.recordFlag = null !== (e = t.recordFlag) && void 0 !== e ? e : {}),
            (t.recordFlag.guide = null !== (e = t.recordFlag.guide) && void 0 !== e ? e : i.GuideStep.NONE),
            null == this.getLocalDataByKey("register_date") &&
                ((e = new Date()),
                    this.setLocalData({ register_date: e.getTime() }),
                    r.platform.uploadAdEvent("active_register", {}),
                    r.platform.trackUserSetOnce({
                        register_date: e,
                        register_ver: s.env.version,
                        register_platform: r.platform.string(),
                        register_channel: this.getLaunchParam("channel", ""),
                        register_scene: this.getLaunchParam("scene", 0),
                        game: s.env.game
                    }),
                    r.platform.trackEvent("register", {
                        ver: s.env.version,
                        channel: this.getLaunchParam("channel", ""),
                        scene: this.getLaunchParam("scene", 0),
                        platform: r.platform.string()
                    })),
                r.platform.trackUserSet({
                    uid: t.uid,
                    name: t.name || "",
                    device_model: r.platform.getSystemData().model,
                    ver: s.env.version,
                    openID: t.openId || "",
                    platform: r.platform.string()
                }),
                r.platform.preloadVideo(l.VideoUnit[l.VideoUnitType.LONG]),
                c.platformEvent.on(this.onPlatformEvent.bind(this));
        }),
        (h.prototype.loadSetting = function() {
            var t = this,
                e = Object.keys(this.setting);
            (this.setting = r.platform.getStorage("setting") || p),
            e.forEach(function(e) {
                null == t.setting[e] && (t.setting[e] = p[e]);
            });
        }),
        (h.prototype.setSetting = function(e, t) {
            void 0 === t && (t = !0),
                (this.setting = o(o({}, this.setting), e)),
                c.userEvent.emit({ userData: this, kind: "setting" }),
                t && (this.delayFlush(this.setting, "setting"), console.log("flush setting", this.setting));
        }),
        (h.prototype.getSetting = function() {
            return this.setting;
        }),
        (h.prototype.setLocalData = function(e) {
            var t = this.getLocalData();
            (this.localData = o(o({}, t), e)), this.delayFlush(this.localData, "localData", 10);
        }),
        (h.prototype.getLocalData = function() {
            return (
                null == this.localData && (this.localData = r.platform.getStorage("localData") || {}), this.localData
            );
        }),
        (h.prototype.getLocalDataByKey = function(e) {
            return null == this.localData ? null : this.localData[e];
        }),
        (h.prototype.setLocalDataNull = function() {
            (this.localData = null), r.platform.setStorage("localData", {});
        }),
        Object.defineProperty(h.prototype, "fakeUID", {
            get: function() {
                return 10005 + 2 * this.basic.uid;
            },
            enumerable: !1,
            configurable: !0
        }),
        (h.prototype.sync = function(e) {
            (this.basic = r.mergeDeep(this.basic, e)), c.userEvent.emit({ userData: this, kind: "local" });
        }),
        (h.prototype.setUid = function(e) {
            this.basic.userId = e;
        }),
        (h.prototype.getUid = function() {
            return this.basic.userId;
        }),
        (h.prototype.syncLaunchOption = function(e) {
            var t;
            console.log("<<<< syncLaunchOption:", e),
                (this.launchOption.query = {}),
                (this.launchOption = o(o({}, this.launchOption), e)),
                null == this.getLocalDataByKey("register_date") &&
                "" !== (t = this.getLaunchParam("ad_type", "")) &&
                (this.setLocalData({ ad_type: t }),
                    "" !== (t = this.getLaunchParam("addict_type", "")) && this.setLocalData({ addict_type: t }),
                    "" !== (t = this.getLaunchParam("clickid", "")) && this.setLocalData({ clickid: t }));
        }),
        (h.prototype.getLaunchParam = function(e, t) {
            if (null == this.launchOption) return t;
            var n = this.launchOption[e];
            return null == n && null != this.launchOption.query && null != this.launchOption.query[e] ?
                this.launchOption.query[e] :
                t;
        }),
        (h.prototype.delayFlush = function(e, t, n) {
            var o = this;
            void 0 === n && (n = 0);
            var i = this.flushTimeoutKeys[t];
            i && clearTimeout(i),
                (this.flushTimeoutKeys[t] = setTimeout(function() {
                    (o.flushTimeoutKeys[t] = null), r.platform.setStorage(t, e);
                }, 1e3 * n));
        }),
        (h.prototype.incVideoCnt = function() {
            var e = this.getVideoCnt();
            return this.setLocalData({ video_cnt: (e += 1) }), e;
        }),
        (h.prototype.getVideoCnt = function() {
            var e = this.getLocalData().video_cnt;
            return (e = null == e ? 0 : e);
        }),
        (h.prototype.onPlatformEvent = function(e) {
            console.log("onPlatformEvent..1...", e),
                null != e &&
                (e.onShow ||
                    (e.onHide &&
                        (this.saveLocalData(),
                            a.playerInfo.getGameType() === a.gameType.war && this.saveWarData())));
        }),
        (h.prototype.getCellsByIdx = function(e) {
            var t = this.getLocalData().cell_data;
            return null != t && null != t[e] ? t[e] : [];
        }),
        (h.prototype.setCellsByIdx = function(e, t) {
            var n;
            null != e && null != t ?
                (((n = null == (n = this.getLocalData().cell_data) ? {} : n)[e] = t),
                    this.setLocalData({ cell_data: n })) :
                console.log("setCellsByIdx error idx:", e, " data:", t);
        }),
        (h.prototype.isBannerAdUser = function() {
            return "banner" === this.getLocalDataByKey("ad_type");
        }),
        (h.prototype.saveLocalData = function() {
            r.platform.setStorage("localData", this.localData);
        }),
        (h.prototype.setWarData = function(e) {
            var t = this.getWarData();
            (this.warData = o(o({}, t), e)), this.delayFlush(this.warData, "warData", 10);
        }),
        (h.prototype.getWarData = function() {
            return null == this.warData && (this.warData = r.platform.getStorage("warData") || {}), this.warData;
        }),
        (h.prototype.saveWarData = function() {
            r.platform.setStorage("warData", this.warData);
        }),
        h);

function h() {
    (this.basic = { uid: 0, userId: "123", openId: "test2", isNew: !1, envConf: {}, subscribeCnt: {} }),
    (this.TotalLevel = 1),
    (this.setting = { effectSound: !0, bgmSound: !0, vibrate: !0 }),
    (this.localData = null),
    (this.warData = null),
    (this.network = { networkType: "none" }),
    (this.launchOption = { scene: 0, query: {} }),
    (this.flushTimeoutKeys = {}),
    (this.enterAt = Date.now()),
    (this.loginAt = null);
}
(n.UserData = e), (n.userData = new e());